<?php
//自动生成,请根据需要修改
namespace app\mqtt\controller;
use app\common\controller\Base;
use think\facade\Request;
use think\Db;
/**
* @title 在线客户接口
* @description 在线客户说明
* @group mqtt
*/
class MqttClientOnline extends Base{

	/**
	* @title 插入记录
	* @description 插入在线客户数据
	* @author 开发者（范浩婷）
	* @url /mqtt/mqtt_client_online/add
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:account_id type:Int require:1 default:0 other: desc:账号id
	* @param name:mqtt_client_id type:Int require:1 default:0 other: desc:mqtt链接id
	* @param name:online type:Enum require:1 default:0 other: desc:在线(1:在线 0:不在线)
	* @param name:last_time type:Int require:1 default:0 other: desc:最后在线时间
	*
	*
	* @return account_id:账号id
	* @return mqtt_client_id:mqtt链接id
	* @return online:在线
	* @return last_time:最后在线时间
	* @return token:token
	*
	*/
	public function add (){
		//模块 - 输入数据
		$input=input();

		//模块 - 验证器
		$mqtt_client_onlineValidate = new \app\mqtt\validate\MqttClientOnline;
		$validate = $mqtt_client_onlineValidate->scene('except_id')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $mqtt_client_onlineValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 新增  ---
		//插入的数据
		$insert_data = [
			'account_id'=>$input['account_id'],
			'mqtt_client_id'=>$input['mqtt_client_id'],
			'online'=>$input['online'],
			'last_time'=>$input['last_time'],
			'token'=>$input['token'],
		];
		//添加数据
		$insert_res = Db::name('mqtt_client_online')->data($insert_data)->insert();
		if(!$insert_res){
			$msg['msg'] = '插入数据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $insert_res;

		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取列表数据（paginate）
	* @description 获取在线客户的列表数据（分页）
	* @author 开发者（范浩婷）
	* @url /mqtt/mqtt_client_online/get_list
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:account_id type:Int require:1 default:0 other: desc:账号id
	* @param name:mqtt_client_id type:Int require:1 default:0 other: desc:mqtt链接id
	* @param name:online type:Enum require:1 default:0 other: desc:在线(1:在线 0:不在线)
	* @param name:last_time type:Int require:1 default:0 other: desc:最后在线时间
	*
	* @param name:page type:Int require:0 default:0 other: desc:当前页
	* @param name:pagesize type:Int require:0 default:0 other: desc:每页数量
	*
	* @return id:id
	* @return account_id:账号id
	* @return mqtt_client_id:mqtt链接id
	* @return online:在线
	* @return last_time:最后在线时间
	* @return token:token
	*
	*/
	public function get_list (){
		//模块 - 输入数据
		$input=input();

		//查询条件
		$temp_map = [
			['id','=',$input['id']],
			['account_id','=',$input['account_id']],
			['mqtt_client_id','=',$input['mqtt_client_id']],
			['online','=',$input['online']],
			['last_time','=',$input['last_time']],
			['token','like','%'.$input['token'].'%'],
		];
		//去除为空的条件
		$paginate_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($paginate_map,$v);
		}

		//获取数据
		$select_res = Db::name('mqtt_client_online')->where($paginate_map)->paginate();

		// paginate 返回数据
		$msg['list'] = $select_res;

		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取列表数据（select）
	* @description 获取在线客户的列表数据（无分页）
	* @author 开发者（范浩婷）
	* @url /mqtt/mqtt_client_online/get_select
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:account_id type:Int require:1 default:0 other: desc:账号id
	* @param name:mqtt_client_id type:Int require:1 default:0 other: desc:mqtt链接id
	* @param name:online type:Enum require:1 default:0 other: desc:在线(1:在线 0:不在线)
	* @param name:last_time type:Int require:1 default:0 other: desc:最后在线时间
	*
	*
	* @return id:id
	* @return account_id:账号id
	* @return mqtt_client_id:mqtt链接id
	* @return online:在线
	* @return last_time:最后在线时间
	* @return token:token
	*
	*/
	public function get_select (){
		//模块 - 输入数据
		$input=input();

		//查询条件
		$temp_map = [
			['id','=',$input['id']],
			['account_id','=',$input['account_id']],
			['mqtt_client_id','=',$input['mqtt_client_id']],
			['online','=',$input['online']],
			['last_time','=',$input['last_time']],
			['token','like','%'.$input['token'].'%'],
		];
		//去除为空的条件
		$select_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($select_map,$v);
		}

		//获取数据
		$select_res = Db::name('mqtt_client_online')->where($select_map)->select();

		// select 返回数据
		$msg['list'] = $select_res;

		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取单条数据
	* @description 根据ID获取在线客户的指定记录
	* @author 开发者（范浩婷）
	* @url /mqtt/mqtt_client_online/info
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
//    * @param name:account_id type:Int require:1 default:0 other: desc:账号id
//    * @param name:mqtt_client_id type:Int require:1 default:0 other: desc:mqtt链接id
//    * @param name:online type:Enum require:1 default:0 other: desc:在线(1:在线 0:不在线)
//    * @param name:last_time type:Int require:1 default:0 other: desc:最后在线时间
	*
	*
	* @return id:id

    * @return account_id:账号id
    * @return mqtt_client_id:mqtt链接id
    * @return online:在线
    * @return last_time:最后在线时间
    * @return token:token
	*
	*/
	public function info (){
		//模块 - 输入数据
		$input=input();

		//模块 - 验证器
		$mqtt_client_onlineValidate = new \app\mqtt\validate\MqttClientOnline;
		$validate = $mqtt_client_onlineValidate->scene('only_id')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $mqtt_client_onlineValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['id','=',$input['id']],
//            ['account_id','=',$input['account_id']],
////            ['mqtt_client_id','=',$input['mqtt_client_id']],
////            ['online','=',$input['online']],
////            ['last_time','=',$input['last_time']],
////            ['token','like','%'.$input['token'].'%'],

		];
		//去除为空的条件
		$find_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($find_map,$v);
		}

		//获取数据
		$select_res = Db::name('mqtt_client_online')->where($find_map)->find();

		// find 返回数据
		$msg['data'] = $select_res;

		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 更新记录
	* @description 根据ID更新在线客户指定记录的数据
	* @author 开发者（范浩婷）
	* @url /mqtt/mqtt_client_online/edit
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:account_id type:Int require:1 default:0 other: desc:账号id
	* @param name:mqtt_client_id type:Int require:1 default:0 other: desc:mqtt链接id
	* @param name:online type:Enum require:1 default:0 other: desc:在线(1:在线 0:不在线)
	* @param name:last_time type:Int require:1 default:0 other: desc:最后在线时间

	*
	*
	* @return id:id
	* @return account_id:账号id
	* @return mqtt_client_id:mqtt链接id
	* @return online:在线
	* @return last_time:最后在线时间
	* @return token:token
	*
	*/
	public function edit (){
		//模块 - 输入数据
		$input=input();

		//模块 - 验证器
		$mqtt_client_onlineValidate = new \app\mqtt\validate\MqttClientOnline;
		$validate = $mqtt_client_onlineValidate->scene('all_field')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $mqtt_client_onlineValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 修改  ---
		//更新的条件
		$update_date = [
		'id'=>$input['id'],
		];
		//更新的数据
		$update_map = [
			'account_id'=>$input['account_id'],
			'mqtt_client_id'=>$input['mqtt_client_id'],
			'online'=>$input['online'],
			'last_time'=>$input['last_time'],
			'token'=>$input['token'],
		];
		//获取数据
		$update_res = Db::name('mqtt_client_online')->where($update_date)->update($update_map);
		if(!$update_res){
			$msg['msg'] = '更新据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $update_res;

		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 按条件删除记录
	* @description 按条件删除在线客户的数据
	* @author 开发者（范浩婷）
	* @url /mqtt/mqtt_client_online/delete
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:account_id type:Int require:1 default:0 other: desc:账号id
	* @param name:mqtt_client_id type:Int require:1 default:0 other: desc:mqtt链接id
	* @param name:online type:Enum require:1 default:0 other: desc:在线(1:在线 0:不在线)
	* @param name:last_time type:Int require:1 default:0 other: desc:最后在线时间
//	* @param name:token type:VarChar require:1 default:0 other: desc:token
	*
	*
	* @return id:id
	* @return account_id:账号id
	* @return mqtt_client_id:mqtt链接id
	* @return online:在线
	* @return last_time:最后在线时间
	* @return token:token
	*
	*/
	public function delete (){
		//模块 - 输入数据
		$input=input();

		//删除的条件
		$temp_map = [
			['id','=',$input['id']],
			['account_id','=',$input['account_id']],
			['mqtt_client_id','=',$input['mqtt_client_id']],
			['online','=',$input['online']],
			['last_time','=',$input['last_time']],
			['token','=',$input['token']],
		];
		$delete_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2] == null || $v[2] == ''){
				continue;
			}
			array_push($delete_map,$v);
		}
		if(empty($delete_map)){
			$msg['msg'] = '删除条件不能为空';
			return $this->errorJson($msg);
		}

		//删除数据
		$delete_res = Db::name('mqtt_client_online')->where($delete_map)->delete();
		if(!$delete_res){
			$msg['msg'] = '删除数据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $delete_res;

		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}

}
